package com.taotao.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.domain.Order;
import com.taotao.order.service.IOrderService;

/**
 * 订单控制层
 * 
 * @author Administrator
 *
 */
@Controller
public class OrderController {
	@Autowired
	private IOrderService orderService;

	/**
	 * 添加订单
	 * 
	 * @param order
	 * @return
	 */
	@RequestMapping(value = "/create", method = RequestMethod.POST)
	@ResponseBody
	private TaotaoResult create(@RequestBody Order order) {
		TaotaoResult taotaoResult = this.orderService.createOrder(order, order.getOrderItems(),
				order.getOrderShipping());
		return taotaoResult;
	}

	/**
	 * 根据订单id查询订单信息
	 * 
	 * @param orderId
	 * @return
	 */
	@RequestMapping(value = "/info/{orderId}")
	@ResponseBody
	public TaotaoResult getOrderItemByOrderId(@PathVariable String orderId) {
		TaotaoResult taotaoResult = this.orderService.getOrderItemByOrderId(orderId);
		if (200 == taotaoResult.getStatus()) {
			return taotaoResult;
		}
		return null;

	}

	/**
	 * 根据用户名查询订单信息
	 * 
	 * @param userId
	 * @param page
	 * @param rows
	 * @return
	 */
	// http://order.taotao.com/order/list/{userID}/{page}/{count}
	@RequestMapping("/list/{userId}/{page}/{rows}")
	@ResponseBody
	public TaotaoResult getOrderItemByUserIdWithPage(@PathVariable Long userId, @PathVariable Integer page,
			@PathVariable Integer rows) {
		TaotaoResult taotaoResult = this.orderService.getOrderItemByUserIdWithPage(userId, page, rows);
		if (200 == taotaoResult.getStatus()) {
			return taotaoResult;
		}
		return null;
	}

	/**
	 * <<<<<<< HEAD 修改订单的状态 ======= 修改订单的状态 >>>>>>> 订单系统完成
	 * 
	 * @param orderId
	 * @param status
	 * @param paymentTime
	 * @return
	 */
	// http://order.taotao.com/order/changeStatus
	@RequestMapping("/changeStatus")
	@ResponseBody
	public TaotaoResult changeStatus(String orderId, Integer status, Long paymentTime) {
		TaotaoResult taotaoResult = this.orderService.changeStatus(orderId, status, paymentTime);
		if (200 == taotaoResult.getStatus()) {
			return taotaoResult;
		}
		return null;
	}

}
